/*
 * @Author: your name
 * @Date: 2021-10-04 12:57:45
 * @LastEditTime: 2021-10-04 14:01:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \diff\src\mysnabbdom\createElement.js
 */
// 创建 节点，将vnode创建为DOM插入到pivot这个元素之前
export default function createElement(vnode){
 
     // 创建节点  
     let domNode = document.createElement(vnode.sel);
     // 判断是否有文本节点
     if(vnode.text!='' && (vnode.children==undefined || vnode.children.length==0) ){
            domNode.innerText=vnode.text;
            // 将新节点上树，让标杆元素的父元素嗲用insertBefore方法，将新节点插入到标杆节点之前
           
     }else if(Array.isArray(vnode.children) && vnode.children.length>0 ){
            let len = vnode.children.length;
            for(let i=0,c=null;i<len;i++){
                 c = vnode.children[i]
                 // 递归创建
                 let treeDom = createElement(c)
                 domNode.appendChild(treeDom);
            }
     }
     vnode.elm = domNode; 
     return vnode.elm
}